Skip to content

Fixing issue with single quotes being lost from input#27

Merged
dvcrn merged 2 commits into
dvcrn:mainfrom
j-wang:main
Feb 4, 2026
Merged

Fixing issue with single quotes being lost from input#27
dvcrn merged 2 commits into
dvcrn:mainfrom
j-wang:main

Conversation

@j-wang
Copy link
Copy Markdown
Contributor

@j-wang j-wang commented Feb 3, 2026

This impacts create_record and update_record_content at minimum. Fixes #26.

I've traced the cause, which is a fairly simple fix in execute.ts's escape pattern. I've tested it on records myself in Claude, which is also working.

All tests and linting pass—which shouldn't be surprising, given how small of a change this is.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @j-wang, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a critical bug where single quotes in input data were being lost when processed by AppleScript/JXA commands, specifically impacting create_record and update_record_content. The fix involves a precise adjustment to the character escaping logic in execute.ts, ensuring that data integrity is maintained for operations involving single quotes.

Highlights

  • Single Quote Escaping Fix: Corrected the regular expression used to escape single quotes within JavaScript for Automation (JXA) scripts executed via osascript. The previous pattern '' was insufficient for shell interpretation, leading to data loss. The new pattern '\'' properly escapes single quotes, preserving data integrity.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/applescript/execute.ts
    • Modified the script.replace method within the executeJxa function to correctly escape single quotes for shell command execution. The old /'/g, "''" has been updated to /'/g, "'\\''".
Activity
  • The author identified the root cause of the issue in execute.ts's escape pattern.
  • The fix has been tested on records in Claude and confirmed to be working as expected.
  • All existing tests and linting checks pass, indicating no regressions from this change.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly fixes an issue where single quotes in input were being lost due to improper shell escaping. While the fix works, I've provided a suggestion to refactor the code to use child_process.execFile instead of child_process.exec. This is a more robust and secure approach as it avoids shell interpretation entirely, removing the need for manual string escaping. This would prevent this class of bug from recurring. Additionally, it would be beneficial to add a regression test for this fix to ensure it doesn't happen again.

Comment thread src/applescript/execute.ts Outdated
export const executeJxa = <T>(script: string): Promise<T> => {
return new Promise((resolve, reject) => {
const command = `osascript -l JavaScript -e '${script.replace(/'/g, "''")}'`;
const command = `osascript -l JavaScript -e '${script.replace(/'/g, "'\\''")}'`;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

While this fix for escaping single quotes is correct, constructing shell commands by interpolating strings is fragile and can be a security risk (shell injection). A more robust and secure approach is to use child_process.execFile, which passes arguments to the command directly, bypassing the shell. This eliminates the need for manual escaping.

I recommend refactoring this function to use execFile. You would need to change the import on line 1 from exec to execFile, and then modify the execution logic as follows:

// in executeJxa function body
execFile("osascript", ["-l", "JavaScript", "-e", script], (error, stdout, stderr) => {
  // ... rest of the callback remains the same
});

This change makes the code safer, simpler, and removes a whole class of potential escaping-related bugs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I agree with this. I suppose it depends on whether @dvcrn is more comfortable with this vs. literally two extra characters, but I'll make the change and update.

@j-wang
Copy link
Copy Markdown
Contributor Author

j-wang commented Feb 3, 2026

Retested, and it's all working from Claude calling it without issues.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively resolves the issue of single quotes being lost from input by refactoring the external command execution. The transition from child_process.exec to child_process.execFile is a crucial improvement, as it enhances security by preventing potential shell injection vulnerabilities and correctly handles script arguments without relying on manual string escaping. This change represents a more robust and recommended practice for executing external processes.

return new Promise((resolve, reject) => {
const command = `osascript -l JavaScript -e '${script.replace(/'/g, "''")}'`;
exec(command, (error, stdout, stderr) => {
execFile("osascript", ["-l", "JavaScript", "-e", script], (error, stdout, stderr) => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-high high

The change from exec to execFile with an array of arguments is a significant security enhancement. The previous method of constructing a command string and manually escaping characters was inherently vulnerable to shell injection if not meticulously handled for all special characters. execFile bypasses the shell's interpretation of arguments, making the execution much safer and more reliable, directly addressing the issue of lost single quotes.

@dvcrn dvcrn merged commit 19a2207 into dvcrn:main Feb 4, 2026
3 checks passed
@dvcrn
Copy link
Copy Markdown
Owner

dvcrn commented Feb 4, 2026

Will try to get this released today, thanks for the PR! ❤️

@dvcrn
Copy link
Copy Markdown
Owner

dvcrn commented Feb 4, 2026

Released in 1.7.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Single quotes/apostrophes are lost in create and update record

2 participants